<template>
  <div class="echarts" ref="echarts"></div>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/resize'
import { mapState } from 'vuex'
export default {
  name: 'LineChart',
  mounted() {
    this.myEcharts = echarts.init(this.$refs.echarts)
    this.myEcharts.setOption({
      xAxis: {
        type: 'category',
        show: false,
        boundaryGap: true
      },
      yAxis: {
        show: false
      },
      series: [
        {
          type: 'line',
          smooth: true,
          itemStyle: { opacity: 0 },
          lineStyle: {
            color: 'purple'
          },
          areaStyle: {
            color: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: '#D9C4F5' // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: '#fff' // 100% 处的颜色
                }
              ],
              global: false // 缺省为 false
            }
          }
        }
      ],
      grid: {
        left: 0,
        right: 0,
        top: 0,
        bottom: 0
      },
      silent: true
    })
  },
  computed: {
    ...mapState({
      visitTrend: state => state.home.homeData.visitTrend
    })
  },
  watch: {
    visitTrend(val) {
      this.myEcharts.setOption({
        series: { data: val }
      })
    }
  },
  mixins: [resize]
}
</script>

<style lang="scss">
.echarts {
  width: 100%;
  height: 50px;
}
</style>
